<template>
    <div>
        <div class="form-section">
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>通知标题</label>
                    <i class="iconfont icon-required"></i>
                </div>
                <div>
                    <input type="text"
                           v-model="title"
                           placeholder="请输入">
                </div>
            </div>
            <div class="form-item form-item-style2">
                <div class="label-title space-between">
                    <div class="space-between">
                        <label>发布范围</label>
                        <i class="iconfont icon-required"></i>
                    </div>
                    <span @click="personPropShow = true">请选择</span>
                </div>
                <div>
                    <p class="textarea">{{issueDeptName}}</p>
                </div>
            </div>
            <div class="form-item form-item-style2">
                <div class="label-title space-between">
                    <div class="space-between">
                        <label>通知内容</label>
                        <i class="iconfont icon-required"></i>
                    </div>
                </div>
                <div>
                    <textarea v-model="content"
                              placeholder="请输入"></textarea>
                </div>
            </div>
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>重要通知</label>
                    <i class="iconfont icon-required"></i>
                </div>
                <group>
                    <popup-picker :data="list1"
                                  v-model="significance"
                                  placeholder="请选择"></popup-picker>
                </group>
            </div>
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>发布人</label>
                </div>
                <div>
                    <p>{{userInfo.username}}</p>
                </div>
            </div>
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>发布日期</label>
                </div>
                <div>
                    <p>{{IssueTime}}</p>
                </div>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <div class="form-section">
            <div class="form-item form-item-style2">
                <div class="label-title space-between">
                    <div class="space-between">
                        <label>图片</label>
                    </div>
                    <span>当前共{{uploadLength}}张图片</span>
                </div>
                <div class="upload-wrap">
                    <upload @setFormData="setFormData"></upload>
                </div>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <div class="btns">
            <button class="green width200"
                    @click="addInform">保存</button>
        </div>
        <issueScopeUsers :personPropShow="personPropShow"
                         :selectUsers="selectUsers"></issueScopeUsers>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
import upload from '@/commonComponents/upload/index'
import formatDate from '@/utils/formatDate'
import issueScopeUsers from '@/commonComponents/issueScopeUsers'
import { setTimeout } from 'timers'
export default {
    name: 'addInform',
    components: {
        upload,
        myMenu,
        issueScopeUsers
    },
    data () {
        return {
            userInfo: {},
            title: '',
            IssueTime: formatDate(), // 发布时间
            issueDeptName: '', // 发布范围人员
            issueDeptId: '', // 发布范围人员id
            content: '',
            list1: [['是', '否']],
            significance: ['是'], // 是否是重要通知
            issueDate: '', // 发布时间
            uploadLength: 0,
            uploadImgFormData: null,
            personPropShow: false
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
    },
    methods: {
        setFormData (formData, uploadLength) {
            this.uploadImgFormData = formData
            this.uploadLength = uploadLength
        },
        selectUsers (issueDeptName, issueDeptId) {
            this.personPropShow = false
            this.issueDeptName = issueDeptName
            this.issueDeptId = issueDeptId
        },
        addInform () {
            if (!this.title) {
                this.$vux.toast.text('请输入通知标题')
                return false
            } else if (!this.issueDeptId) {
                this.$vux.toast.text('请选择发布范围')
                return false
            } else if (!this.content) {
                this.$vux.toast.text('请输入通知内容')
                return false
            }
            this.$vux.loading.show({
                text: '提交中...'
            })
            let params = {
                'allowPaging': true,
                'business': 'ReportAffiche',
                'data': {
                    'IsImportant': this.significance[0] == '否' ? 0 : 1, // 是否重要通知,0否1是
                    'IssueTime': this.IssueTime, // 发布日期
                    'content': this.content, // 通知内容
                    'issueDeptId': this.issueDeptId, // 接收范围人员id
                    'issueDeptName': this.issueDeptName, // 接收阀内人员名称
                    'issuer': this.userInfo.userid, //
                    'save': false,
                    'status': '1',
                    'title': this.title// 标题
                },
                'method': 'new',
                'pageIndex': 0,
                'pageSize': 0,
                'tokenId': this.userInfo.tokenid,
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params, this.uploadImgFormData)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.$vux.toast.text('新增成功')
                        setTimeout(() => {
                            this.$router.go(-1)
                        }, 1000)
                    }
                }).catch((response) => {
                })
        }
    }
}
</script>
<style scoped>
</style>
